<template>
  <el-container>
    <BomTree style="margin-top: 16px" @on-choose-region="filetrStation" />
    <el-main>
      <div class="default-main ba-table-box">
        <Schedule />
      </div>
      <div class="calendar-box">
        <Calendar />
      </div>
    </el-main>
  </el-container>
</template>
<script setup lang="ts">
import { ref, provide, onMounted, reactive, onBeforeUnmount } from "vue";
import BomTree from "./components/aside.vue";
import { useDictionary } from "@/store/backend/tool/dictionary";
import { useFactoryEquipment } from "@/store/backend/FactoryM/equipmentUnit";
import { useFactoryStation } from "@/store/backend/FactoryM/stationInfo";
import { useDept } from "@/store/backend/SysM/dept";
import { useFactorySchedule } from "@/store/backend/FactoryM/factorySchedule";
import Calendar from "./calendar.vue";
import Schedule from "./Schedule.vue";
import useCurrentInstance from "@/utils/useCurrentInstance";
import { useFactoryClass } from "@/store/backend/FactoryM/class";

const dictionary = useDictionary();
const equipUnit = useFactoryEquipment();
const station = useFactoryStation();
const schedule = useFactorySchedule();
const equipClass = useFactoryClass();
const dept = useDept();
//全局事件总线
const { proxy } = useCurrentInstance();

//接收工作中心树传递过来的数据
const filetrStation = (row: any, node: any) => {
  console.log("接收工作中心树传递过来的数据", row);

  if (node.checkedKeys.length == 0) {
    //表示取消选择直接调用刷新表单方法
    // baTable.comSearch.form = Object.assign(baTable.comSearch.form, {
    //   regions: region.regionIds + "",
    // });
    schedule.$patch((state: any) => {
      state.equipmentScheduleInfo = {};
      state.parentScheduleNode = node.halfCheckedKeys;
    });
    proxy.eventBus.emit("getScheduleOfFactory", {});
  } else {
    //获取设备数据
    schedule.$patch((state: any) => {
      state.equipmentScheduleInfo = row;
      state.parentScheduleNode = node.halfCheckedKeys;
    });
    //查询设备排班数据
    proxy.eventBus.emit("getScheduleOfFactory", row);
  }
};

// 实例化表格后，将 baTable 的实例提供给上下文
provide("dictionary", dictionary);
provide("equipUnit", equipUnit);
provide("station", station);
provide("dept", dept);
provide("schedule", schedule);
provide("equipClass", equipClass);

onBeforeUnmount(() => {
  schedule.$patch((state: any) => {
    state.equipmentScheduleInfo = {};
    state.parentScheduleNode = {};
  });
});
</script>
<style lang="scss" scoped>
.default-main {
  margin: 0px !important;
}
</style>
